﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PolePositionMobile
{
    public partial class Calendar : UserControl
    {
        #region Private Members
        private DateTime m_Value = DateTime.MinValue;
        #endregion
        #region Public Properties
        public Font CalendarFont
        {
            set { datCalendar.CalendarFont = value; }
            get { return datCalendar.CalendarFont; }
        }
        public string CustomFormat
        {
            set { datCalendar.CustomFormat = value; }
            get { return datCalendar.CustomFormat; }
        }
        public new Font Font
        {
            set { datCalendar.Font = value; }
            get { return datCalendar.Font; }
        }
        public DateTimePickerFormat Format
        {
            set { datCalendar.Format = value; }
            get { return datCalendar.Format; }
        }
        public DateTime Value
        {
            set
            {
                m_Value = value;
                datCalendar.Tag = false;
                if (m_Value != DateTime.MinValue)
                {
                    datCalendar.Value = m_Value;
                    txtDisplay.Text = datCalendar.Text;
                }
                else
                {
                    datCalendar.Value = DateTime.Now.ToUniversalTime();
                    txtDisplay.Text = "";
                }
                datCalendar.Tag = true;
            }
            get
            {
                return m_Value;
            }
        }
        #endregion
        public Calendar()
        {
            InitializeComponent();
        }
        private void cmdClear_Click(object sender, EventArgs e)
        {
            Value = DateTime.MinValue;
        }
        private void datCalendar_ValueChanged(object sender, EventArgs e)
        {
            if (datCalendar.Tag == null || (bool)datCalendar.Tag)
                Value = datCalendar.Value;
            datCalendar.Tag = true;
        }
        private void txtDisplay_GotFocus(object sender, EventArgs e)
        {
            datCalendar.Show();
        }
    }
}
